import axios, { AxiosRequestConfig, AxiosResponse } from "axios";

const server = axios.create({
  baseURL: "http://localhost:3000",
  timeout: 5000,
});

server.interceptors.request.use((config: AxiosRequestConfig) => {
  // @ts-ignore
  config.headers["token"] = window.localStorage.getItem("token") || "abc";
  return config;
});

server.interceptors.response.use(
  (response: AxiosResponse) => {
    return response.data;
  },
  (err) => {
    // if(err.response.statuscode === 401){
    //   //xxxx
    // }
  }
);

export default server;
